﻿// // See https://aka.ms/new-console-template for more information
//

using System.Net;
using System.Net.Sockets;
using Client;
using Core;

var client = new PlayClient();

client.RegisterReplyHandle(BaseCommand.Types.CommandType.AddOrder, OnAddOrderAsync);

await client.StartAsync();

var reply = await client.LoginAsync("kk", "hhhh");

Console.WriteLine(reply.SuccessFul);

async Task<BaseCommand> OnAddOrderAsync(BaseCommand command)
{
    var order = command.Order;

    Console.WriteLine("添加订单");

    await Task.Delay(TimeSpan.FromSeconds(25));

    return new BaseCommand
    {
        SuccessFul = true,
        RequestId = command.RequestId,
        Key = BaseCommand.Types.CommandType.AddOrderReply,
    };
}

while (true)
{
    await Task.Delay(1000);
}


//
// BasePacket request = new LoginPacket
// {
//     Username = "wujun",
//     Password = "wujun520.",
//     Id = 1,
// };
//
// var body1 = request.EncodeBody();
//
//
//
// var loginRequest = new BasePacket(new LoginPacket
// {
//     Username = "wujun",
//     Password = "wujun520.",
// })
// {
//     Key = CommandKey.Login,
// };
//
// var stream = new MemoryStream();
//
// ProtoBuf.Serializer.Serialize(stream, loginRequest);
//
// var body = stream.ToArray();
//
// stream = new MemoryStream(body);
//
// var type = typeof(BasePacket).MakeGenericType(typeof(LoginPacket));
//
// var s = ProtoBuf.Serializer.Deserialize(type, stream);
//
// loginRequest = ProtoBuf.Serializer.Deserialize<BasePacket>(stream);
//
// Console.WriteLine("Hello, World!");